package com.neuedu.ylbx.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.neuedu.ylbx.dto.TreatmentDto;
import com.neuedu.ylbx.pojo.DiagnosisTreatment;
import com.neuedu.ylbx.pojo.DrugInfo;
import com.neuedu.ylbx.service.TreatmentService;
import com.neuedu.ylbx.utils.ResultVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/treatment")
@Tag(name = "诊疗项目管理")
@CrossOrigin
public class TreatmentController {    //诊疗项目管理
    @Autowired
    TreatmentService treatmentService;

    @GetMapping("/treatmentpage")
    @Operation(summary = "获取诊疗项目列表")
    public ResultVo listTreatmentPage(){
        return ResultVo.ok(treatmentService.list());
    }
    @PostMapping("/addtreatment")
    @Operation(summary = "添加诊疗项目")
    public ResultVo addTreatment(DiagnosisTreatment diagnosisTreatment){
        treatmentService.save(diagnosisTreatment);
        return ResultVo.ok("添加成功");
    }
    @PutMapping("/updatetreatment")
    @Operation(summary = "修改诊疗项目信息")
    public ResultVo updateTreatment(DiagnosisTreatment diagnosisTreatment){
        UpdateWrapper<DiagnosisTreatment> updateWrapper = new UpdateWrapper<DiagnosisTreatment>();
        updateWrapper.eq("id",diagnosisTreatment.getId());
        treatmentService.update(diagnosisTreatment,updateWrapper);
        return ResultVo.ok("修改成功");
    }
    @DeleteMapping("/deletetreatment")
    @Operation(summary = "删除诊疗项目")
    public ResultVo deleteTreatment(DiagnosisTreatment diagnosisTreatment){
        treatmentService.removeById(diagnosisTreatment);
        return ResultVo.ok("删除成功");
    }
    @DeleteMapping("/deletetreatments")
    @Operation(summary = "批量删除诊疗项目")
    public ResultVo deleteTreatments(@RequestBody List<Long> treatmentIDs){
        treatmentService.removeByIds(treatmentIDs);
        return ResultVo.ok("批量成功");
    }
}
